%%
%

clear all
close all
clc

%% Sequence names
% Must be manually changed by user before running script.


PATIENT_ID(1,:)='stikov_nikola_20120329_100023_';

GOLDSTANDARD_ID(1,:) = [PATIENT_ID(1,:) '43' '_mri.mnc'];

% VFA 2x2x5
SEQ_ID(1,:)=2;     
SEQ_ID(2,:)=3;
SEQ_ID(3,:)=4;
SEQ_ID(4,:)=5;
SEQ_ID(5,:)=6;

% AFI 2x2x5
SEQ_ID(6,:)=7;
SEQ_ID(7,:)=8;

% VFA 1x1x1
SEQ_ID(8,:)=9;
SEQ_ID(9,:)=10;


EXCEPTION_CASE(1,:)=7;
EXCEPTION_ID(1,:)='d1';

EXCEPTION_CASE(2,:)=8;
EXCEPTION_ID(2,:)='d2';

% VFA 1x1x5
SEQ_ID(10,:)=11;
SEQ_ID(11,:)=12;

%VFA 1x1x5 (4 averages)
SEQ_ID(12,:)=13;
SEQ_ID(13,:)=14;

%% Create cell array containing sequence names to be registered
%

SEQ_NAME = cell(length(SEQ_ID(:,1)),1);

for k=1:length(SEQ_ID(:,1))
    
    SEQ_NAME(k,1)=cellstr([PATIENT_ID num2str(SEQ_ID(k,:))]);
    
    for m=1:length(EXCEPTION_CASE(:,1))

        if EXCEPTION_CASE(m,:)==SEQ_ID(k,:)
            
            SEQ_NAME(k,1) = cellstr([char(SEQ_NAME(k,1)) EXCEPTION_ID(m,:)]);
            
        end
        
    end
    
    
    SEQ_NAME(k,1) = cellstr([char(SEQ_NAME(k,1)) '_mri.mnc']);
    
end

%% Registration
%

%B = eval([mincblah blah, 'studyName' 'templateImageID' '_mri.mnc'])

for k=1:length(SEQ_NAME(:,1))
    system(['minctracc -clobber -lsq6' ' ' char(SEQ_NAME(k,1)) ' ' GOLDSTANDARD_ID(1,:) ' ' 'reg' num2str(k) '.xfm'])
    system(['mincresample -clobber -like' ' ' char(SEQ_NAME(k,1)) ' ' '-transform' ' ' 'reg' num2str(k) '.xfm' ' ' char(SEQ_NAME(k,1)) ' ' 'REG_SEQ' num2str(k) '.mnc'])
end
    

